/*
 * @(#)Synset.java	1.0 08/01/07
 *
 * Copyright 2007 Fabio Gasparetti. All rights reserved.
 */

package org.tabularium.text.nlp.wordnet;

import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 * A synonym set, that is a set of words that are interchangeable in some
 * context without changing the truth value of the preposition in which they are
 * embedded.
 * 
 * @author Fabio Gasparetti
 * @version 1.0, 08/01/07
 */

public abstract class Synset implements Comparable {
	public static final String STANDARD_GLOSS_DELIMS = ";\"";

	public abstract int getPOS();

	public abstract String getId();

	/**
	 * Every synset has a 'gloss', composed of a definition and/or example
	 * sentences for the synset.
	 * 
	 * @return
	 */
	public abstract String getGloss();

	/**
	 * Given a gloss string, returns the definition and the single sentences in
	 * a String array.
	 * 
	 * @param gloss
	 * @param glossDelims
	 * @return
	 */
	public static String[] splitGloss(String gloss, String glossDelims) {
		if (gloss.length() == 0)
			return new String[0];
		int i = gloss.indexOf(';');
		if (i < 0)
			return new String[] { gloss };
		ArrayList ss = new ArrayList();
		ss.add(gloss.substring(0, i));

		StringTokenizer tknzr = new StringTokenizer(gloss.substring(i),
				glossDelims);
		while (tknzr.hasMoreTokens()) {
			String s = tknzr.nextToken();
			s = s.trim();
			if (s.length() > 0)
				ss.add(s.trim());
		}
		return (String[]) ss.toArray(new String[] {});
	}

	public static void main(String[] args) {
		try {
			String[] ww = Synset
					.splitGloss(
							"traverse or cover by walking; \"Walk the tightrope\"; \"Paul walked the streets of Damascus\"; \"She walks 3 miles every day\"",
							Synset.STANDARD_GLOSS_DELIMS);
			for (int j = 0; j < ww.length; j++) {
				System.out.println(ww[j]);
			}

		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

}
